<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__body clearfix">
      <div class="top_div">
        <div class="info_div">
          <div class="img_warp">
            <img src="../assets/img/header_icon.png" />
          </div>
          <div class="text_left">土石方清运管理系统</div>
          <div class="text_right">
            <span>重庆市城市建设土地发展有限责任公司</span>
          </div>
          <div class="box_right">
            <el-menu
              class="site-navbar__menu site-navbar__menu--right"
              mode="horizontal"
            >
              <el-menu-item class="site-navbar__avatar" index="3">
                <el-dropdown :show-timeout="0" placement="bottom">
                  <span class="el-dropdown-link">
                    <img src="~@/assets/img/avatar.png" :alt="userName" /><span
                      style="color:#fff"
                      >{{ userName }}</span
                    >
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="updatePasswordHandle()"
                      >修改密码</el-dropdown-item
                    >
                    <el-dropdown-item @click.native="logoutHandle()"
                      >退出</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </el-menu-item>
            </el-menu>
          </div>
        </div>
      </div>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password
      v-if="updatePassowrdVisible"
      ref="updatePassowrd"
    ></update-password>
  </nav>
</template>

<script>
import UpdatePassword from "./main-navbar-update-password";
import { clearLoginInfo } from "@/utils";
export default {
  data() {
    return {
      updatePassowrdVisible: false
    };
  },
  components: {
    UpdatePassword
  },
  computed: {
    navbarLayoutType: {
      get() {
        return this.$store.state.common.navbarLayoutType;
      }
    },
    sidebarFold: {
      get() {
        return this.$store.state.common.sidebarFold;
      },
      set(val) {
        this.$store.commit("common/updateSidebarFold", val);
      }
    },
    mainTabs: {
      get() {
        return this.$store.state.common.mainTabs;
      },
      set(val) {
        this.$store.commit("common/updateMainTabs", val);
      }
    },
    userName: {
      get() {
        return this.$store.state.user.name;
      }
    }
  },
  methods: {
    // 修改密码
    updatePasswordHandle() {
      this.updatePassowrdVisible = true;
      this.$nextTick(() => {
        this.$refs.updatePassowrd.init();
      });
    },
    // 退出
    logoutHandle() {
      this.$confirm(`确定进行[退出]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/sys/logout"),
            method: "post",
            data: this.$http.adornData()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              clearLoginInfo();
              this.$router.push({ name: "login" });
            }
          });
        })
        .catch(() => {});
    }
  }
};
</script>
<style scoped lang="scss">
.top_div {
  width: 100%;
  height: 100%;
  background: url("../assets/img/header.png") center center no-repeat;
  background-size: 100%;
  .info_div {
    display: flex;
    align-items: center;
    padding-top: 10px;
    box-sizing: border-box;
    .img_warp {
      width: 122px;
      height: 50px;
      margin-left: 63px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .text_left {
      font-size: 32px;
      color: rgba(255, 255, 255, 0.84);
      line-height: 32px;
      letter-spacing: 5px;
      margin-left: 49px;
    }
    .text_right {
      margin-left: 130px;
      margin-bottom: 10px;
      span {
        font-size: 24px;
        background-image: -webkit-linear-gradient(bottom, #0064ff, #ffffff);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
    .box_right {
      margin-left: auto;
      .site-navbar__avatar {
        height: 48px;
      }
      .site-navbar__menu {
        background-color: transparent;
      }
      .site-navbar__menu:hover,
      .site-navbar__avatar:hover {
        background-color: transparent !important;
      }
      .site-navbar__menu .site-navbar__menu--right .el-menu--horizontal {
        border-bottom: 0px !important;
      }
    }
  }
}
.site-navbar__body {
  background-color: #031c37;
  height: 91px;
}
.el-menu--horizontal {
  border-bottom: 0px !important;
}
.el-menu--horizontal > .el-menu-item {
  line-height: 20px;
}
</style>
